# Copyright (C) 2009 Samuel Abels, http://debain.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
import string

class Blob(object):
    def __init__(self, data, mime_type = 'unknown'):
        self.id        = None
        self.name      = ''
        self.revision  = 0
        self.deleted   = False
        self.data      = data
        self.text      = None
        self.mime_type = mime_type


    @classmethod
    def from_db(self, data, mime_type = 'unknown'):
        return Blob(data, mime_type)


    def mime_type(self):
        return self.mime_type


    def set_text(self, text):
        self.text = text


    def __str__(self):
        if self.text is not None:
            return self.text
        return self.bin().replace('\x00', '')


    def bin(self):
        return str(self.data)
